package Operation;

import Book.BookList;

import java.util.Scanner;

public class DeleteBook implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入您所要删除的书的名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for(int i = 0; i < bookList.getUsedBookList(); i++){
            if(name.equals(bookList.GetBook(i).getName())){
                System.out.println("您要删除的图书的信息如下");
                System.out.println(bookList.GetBook(i).toString());
                for (int j = i;j < bookList.getUsedBookList() - 1;j ++){
                    bookList.setBook(j,bookList.GetBook(j + 1));
                }
                bookList.setUsedBookList(bookList.getUsedBookList() - 1);
                bookList.setBook(bookList.getUsedBookList(), null);
                System.out.println("删除成功");
                return;
            }
        }
        System.out.println("*****没有找到您要删除的图书*****");
    }
}
